import turtle
import math

def draw_square(pen, x, y, length):
    pen.penup()
    pen.goto(x - length / 2, y - length / 2)
    pen.pendown()
    for _ in range(4):
        pen.forward(length)
        pen.left(90)

def draw_board(pen, j):
    pen.color('black')
    pen.pensize(1)

    length_j = 50 * (j + 1)

    # 绘制开始的三个方块
    center_x = -length_j / 2 + length_j + 150 * j  # 中心点的 x 坐标
    center_y = -length_j / 2  # 中心点的 y 坐标

    # 绘制其他方块
    for i in range(1, 3):
        length_i = 50 * (i + 1)
        offset = (length_j - length_i) / 2  # 需要位移的偏移量
        draw_square(pen, center_x + offset, center_y + offset, length_i)
        center_y += offset * 2  # 更新下一个方块的中心 y 坐标

    draw_square(pen, -150 / 2 + 150 * j, -150 / 2 + 150 * j, length_j)
    a1 = math.sqrt(length_j * length_j + length_j * length_j)
    pen.penup()
    pen.goto(-75 + 150 * j, 150 / 2 + 150 * j)
    pen.pendown()
    pen.setheading(-45)
    pen.forward(a1)

    pen.color('red')
    pen.pensize(3)
    draw_square(pen, -50 + 150 * j, -50 + 150 * j, 100)

canvas = turtle.Screen()
pen = turtle.Turtle()

draw_board(pen, 0)

canvas.exitonclick()
